home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1521 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: aril@cmt.lpr.mail.carel.fi (Ari Lukumies)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using multiple functions in one file
  5. Date: Thu, 11 Jan 1996 13:51:43 GMT
  6. Organization: Carelcomp Forest Oy
  7. Message-ID: <4d3520$kj9@tahko.lpr.carel.fi>
  8. References: <DL00rI.HFr@cunews.carleton.ca>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. abelo@chat.carleton.ca (Andrew Belo) wrote:
  13.  
  14.  
  15. >I have written an example program out of a book and it keeps giving me an
  16. >error that says "Call to undefined function 'butler' in function main()" 
  17. >I am using Borland C++ for Dos, Win and Win 32 Version 4.5.
  18.  
  19. >The book is called C: Step by Step, and the program is as follows.
  20.  
  21. >/* two_func.c -- a program using two functions in one file */ 
  22. >#include <stdio.h>
  23. >main()
  24. >{
  25. >    printf("I will summon the butler function. \n");
  26. >    butler();
  27. >    printf("Yes. Bring me some tea and floppy disks.\n");  
  28. >}
  29. >butler()
  30. >{
  31. >printf("You rang, sir? \n");
  32. >}
  33.  
  34. >Thanx
  35.  
  36. The problem here is that your compiler expects that butler be defined
  37. before it's called. Two solutions: First, you can add a prototype
  38.  
  39.     butler();
  40.  
  41. before the main() function (ie. between #include and main()). Second,
  42. you can move the butler() function before the main().
  43.  
  44. BTW, I'd suggest using ANSI prototyping, if your compiler accepts it:
  45.  
  46.     int    main(void);    /* Sufficient in your case */
  47.     void    butler(void);
  48.  
  49. Later,
  50. AriL
  51.  
  52. All my opinions are mine and mine alone.
  53.  
  54.